home *** CD-ROM | disk | FTP | other *** search
- /* Stuff.c */
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Lists.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <Sound.h>
- #include <TextEdit.h>
- #include <ToolUtils.h>
- #include <Appearance.h>
- #include <stdlib.h>
-
- #include "Globals.h"
- #include "ResourceDefs.h"
- #include "DoScrap.h"
- #include "Miscellany.h"
- #include "Scrolling.h"
- #include "ControlUtils.h"
- #include "Dispatcher.h"
- #include "DDocData.h"
- #include "EverythingEngine.h"
- #include "EverythingDoc.h"
- #include "Stuff.h"
-
-
- static EverythingEngine* GetEngine (Stuff* self);
-
- static void DoUndo (Stuff* self);
- static void DoCut (Stuff* self);
- static void DoCopy (Stuff* self);
- static void DoPaste (Stuff* self);
- static void DoClear (Stuff* self);
- static void DoSelectAll (Stuff* self);
- static void DoShowClipboard (Stuff* self);
-
- static void BuildTextListList (ControlHandle inList);
-
- //----------
- Stuff* NewStuff ()
- {
- Stuff* window;
-
- window = (Stuff*)malloc (sizeof (Stuff));
- Stuff_Init (window);
- SetClassID (window, classStuff);
-
- return window;
- }
-
- //----------
- void DeleteStuff (
- Stuff* window)
- {
- Stuff_Free (window);
- free (window);
- }
-
- //----------
- void Stuff_Create (
- AMDoc* inDoc,
- DDocData* inData)
- {
- Stuff* winObj = NewStuff ();
-
- if (winObj != nil) {
- Stuff_Open (winObj, inDoc, inData);
- }
- }
-
- //----------
- void Stuff_Init (
- Stuff* self)
- {
- }
-
- //----------
- void Stuff_Free (
- Stuff* self)
- {
- }
-
- //----------
- EverythingEngine* GetEngine (
- Stuff* self)
- {
- return (EverythingEngine*) self->super.mDoc->mEngine;
- }
-
- /*----------*/
- void Stuff_Open (
- Stuff* self,
- AMDoc* inDoc,
- DDocData* inData)
- {
- WindowPtr window;
- Handle wftb;
-
- self->super.mDoc = inDoc;
- self->mData = inData;
- AddResponder ((AMSignaler*) self->mData, (AMResponder*) self);
-
- window = GetNewCWindow (WIND_Stuff, nil, (WindowPtr) -1L);
- if (AMEngine_GetFilename (self->super.mDoc->mEngine) [0] != 0) {
- SetWTitle (window, AMEngine_GetFilename (self->super.mDoc->mEngine));
- }
- self->super.mWindow = window;
- ((EverythingDoc*)self->super.mDoc)->mStuffPtr = window;
-
- SetWindowKind (window, 'AM');
- SetWRefCon (window, (long) self);
- SetPort (window);
- SetInfo (window);
-
- wftb = GetResource ('Wftb', WIND_Stuff);
-
- CreateRootControl (window, &self->super.mRootControl);
-
- self->super.vScroll = nil;
- self->super.hScroll = nil;
-
-
- self->mToolsHandle = GetNewControl (CNTL_Tools, window);
- SetWindowItemFont (self->mToolsHandle, wftb, 1);
- SetControlValue (self->mToolsHandle, GetTools (self->mData));
-
- self->mPopupsHandle = GetNewControl (CNTL_Popups, window);
- SetWindowItemFont (self->mPopupsHandle, wftb, 2);
-
- self->mFromValuesList2Handle = GetNewControl (CNTL_FromValuesList2, window);
- EmbedControl (self->mFromValuesList2Handle, self->mPopupsHandle);
- SetWindowItemFont (self->mFromValuesList2Handle, wftb, 3);
- SetControlValue (self->mFromValuesList2Handle, GetFromValuesList2 (self->mData));
-
- self->mFromMenuHandle = GetNewControl (CNTL_FromMenu, window);
- EmbedControl (self->mFromMenuHandle, self->mPopupsHandle);
- SetWindowItemFont (self->mFromMenuHandle, wftb, 4);
- SetControlValue (self->mFromMenuHandle, GetFromMenu (self->mData));
-
- self->mListsHandle = GetNewControl (CNTL_Lists, window);
- SetWindowItemFont (self->mListsHandle, wftb, 5);
-
- self->mTextListHandle = GetNewControl (CNTL_TextList, window);
- EmbedControl (self->mTextListHandle, self->mListsHandle);
- SetWindowItemFont (self->mTextListHandle, wftb, 6);
- BuildTextListList (self->mTextListHandle);
- SetListBoxChoice (self->mTextListHandle, GetTextList (self->mData));
-
- AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- }
-
- /*----------*/
- void Stuff_Close (
- Stuff* self)
- {
- RemoveResponder ((AMSignaler*) self->mData, (AMResponder*) self);
-
- ((EverythingDoc*)self->super.mDoc)->mStuffPtr = nil;
- SetInfo (nil);
- HideWindow (self->super.mWindow);
- DisposeWindow (self->super.mWindow);
-
- DeleteStuff (self);
- }
-
- /*----------*/
- void BuildTextListList (
- ControlHandle inControl)
- {
- ListHandle list;
-
- list = GetListHandle (inControl);
- AddToList ("\pOne", list);
- AddToList ("\pTwo", list);
- AddToList ("\pThree", list);
- AddToList ("\pInfinity", list);
-
- }
-
- /*----------*/
- void Stuff_Track (
- Stuff* self,
- ControlHandle whichControl,
- short whichPart,
- Point where)
- {
- Rect bounds;
- short newValue;
-
- if (whichControl == self->mToolsHandle) {
- if (TrackClick (self->mToolsHandle, where) != 0) {
- SetTools (self->mData, GetControlValue (self->mToolsHandle));
- }
- }
- if (whichControl == self->mFromValuesList2Handle) {
- if (TrackClick (self->mFromValuesList2Handle, where) != 0) {
- SetFromValuesList2 (self->mData, GetControlValue (self->mFromValuesList2Handle));
- }
- }
- if (whichControl == self->mFromMenuHandle) {
- if (TrackClick (self->mFromMenuHandle, where) != 0) {
- SetFromMenu (self->mData, GetControlValue (self->mFromMenuHandle));
- }
- }
- if (whichControl == self->mTextListHandle) {
- if (TrackClick (self->mTextListHandle, where)) {
- SetTextList (self->mData, GetListBoxChoice (self->mTextListHandle));
- }
- }
- }
-
- //----------
- void Stuff_DataChanged (
- Stuff* self,
- long inDataID)
- {
- if (inDataID == idTools) {
- SetControlValue (self->mToolsHandle, GetTools (self->mData));
- }
- if (inDataID == idFromValuesList2) {
- SetControlValue (self->mFromValuesList2Handle, GetFromValuesList2 (self->mData));
- }
- if (inDataID == idFromMenu) {
- SetControlValue (self->mFromMenuHandle, GetFromMenu (self->mData));
- }
- }
-
- /*----------*/
- void Stuff_MouseIn (
- Stuff* self,
- Point where,
- short modifiers)
- {
- Rect bounds;
-
- }
-
- //----------
- void Stuff_ExitCurField (
- Stuff* self)
- {
- ControlHandle focus;
-
- GetKeyboardFocus (self->super.mWindow, &focus);
-
- if (focus == nil) {
- // nothing to exit
-
- }
- }
-
- /*----------*/
- void Stuff_TypeIn (
- Stuff* self,
- char ch)
- {
- ControlHandle focus;
- short keyCode;
-
- GetKeyboardFocus (self->super.mWindow, &focus);
-
- if ((ch == charEnter)
- || (ch == charReturn)) {
- Stuff_ExitCurField (self); // Dispatch
- } else if (ch == charEsc) {
- } else if (ch == charTab) {
- AMWindow_DoTab ((AMWindow*) self, (curEvent.modifiers & optionKey) != 0);
- } else if (focus != nil) {
- keyCode = curEvent.message & keyCodeMask;
- HandleControlKey (focus, keyCode, ch, curEvent.modifiers);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- } else {
- SysBeep (1);
- }
- }
-
- /*----------*/
- void Stuff_Resize (
- Stuff* self)
- {
- /* application-specific code to resize items in window */
- }
-
- /*----------*/
- void Stuff_Scroll (
- Stuff* self,
- short newValue,
- short oldValue)
- {
- /* application-specific code to scroll window */
- if (gWhichScroll == self->super.vScroll) {
- } else { // horizontal
- }
- }
-
- //----------
- void DoUndo (
- Stuff* self)
- {
- } // DoUndo
-
- //----------
- void DoCut (
- Stuff* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TECut (curTE);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- scrapDirty = true;
- }
- } // DoCut
-
- //----------
- void DoCopy (
- Stuff* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TECopy (curTE);
- scrapDirty = true;
- }
- } // DoCopy
-
- //----------
- void DoPaste (
- Stuff* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TEPaste (curTE);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- }
- } // DoPaste
-
- //----------
- void DoClear (
- Stuff* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TEDelete (curTE);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- }
- } // DoClear
-
- //----------
- void DoSelectAll (
- Stuff* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TESetSelect (0, 32767, curTE);
- }
- } // DoSelectAll
-
- //----------
- void DoShowClipboard (
- Stuff* self)
- {
- } // DoShowClipboard
-
- //----------
- Boolean Stuff_DoCommand (
- Stuff* self,
- long inCommand)
- {
- Boolean result = true;
-
- switch (inCommand) {
- case cmdUndo:
- DoUndo (self);
- break;
- case cmdCut:
- DoCut (self);
- break;
- case cmdCopy:
- DoCopy (self);
- break;
- case cmdPaste:
- DoPaste (self);
- break;
- case cmdClear:
- DoClear (self);
- break;
- case cmdSelectAll:
- DoSelectAll (self);
- break;
- case cmdShowClipboard:
- DoShowClipboard (self);
- break;
-
- default:
- result = false;
- } // switch
-
- return result;
- }
-